package cn.zw.design.observer;

import java.util.ArrayList;
import java.util.List;

public class WeatherData implements Subject {
	private  List<Observer> observers;// 用于记录注册过的观察者 
	private float temp; //温度
	private  float pressure; // 气压
	private float humidity; // 湿度
	public WeatherData() {
		observers = new ArrayList<Observer>();
	}

	@Override
	public void registerObserver(Observer observer) {
		observers.add(observer);
	}
	@Override
	public void removeObserver(Observer observer) {
		observers.remove(observer);
	}
	@Override
	public void notifyObservers() {
		for (Observer observer : observers) {
			observer.update(temp, pressure, humidity);
		}
	}
	public void  measurementsChanged(){
		notifyObservers();
	}
	 public  void  setParams(float temp,float pressure,float humidity){
		 this.humidity = humidity;
		 this.pressure = pressure;
		 this.temp = temp;
		 measurementsChanged();
	 }
}
